#include <stdio.h>
#include <string.h>

#define MAXTITL 40
#define MAXAUTH 40
#define BOOKS 100

char * s_gets(char *, int);

struct book
{
    char title[MAXTITL];
    char author[MAXAUTH];
    double value;
};

int main(void)
{
    static struct book library[BOOKS];
    int count = 0;  //统计书籍数量
    int index;      //按索引打印书籍信息

    puts("Please enter the boos title.");
    puts("Press [enter] at the start of a new line to stop.");
    while (count < BOOKS && s_gets(library[count].title, MAXTITL) != NULL && library[count].title[0] != '\0')
    {
        printf("Now enter the author:");
        s_gets(library[count].author, MAXAUTH);
        printf("Now enter the value:");
        scanf("%lf", &library[count].value);
        count++;
        while (getchar() != '\n')
            continue;
        if (count < BOOKS)
            puts("Enter the next title.");
    }
    if (count > 0)
    {
        puts("Here is the list of your books:");
        for (index = 0; index < count; index++)
            printf("%s by %s: $%.2f\n", library[index].title, library[index].author, library[index].value);
    }
    else
        puts("No books? Too bad.");

    return 0;
}

char * s_gets(char * st, int n)
{
    char * ret_val, * find;

    if (ret_val = fgets(st, n, stdin))
    {
        if (find = strrchr(st, '\n'))
            *find = '\0';
        else 
            while (getchar() != '\n')
                continue;
    }

    return ret_val;
}